package question2;

import question1.file.DiGui;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

//C:\Users\29022\Documents\XiaoMiNet\Upupoo\Docker\config\文件夹\新建文件夹\作业及资料\day11-资料
public class BianLiTime {
    public static void main(String[] args) {
        File file = new File("C:\\Users\\29022\\Documents\\XiaoMiNet\\Upupoo\\Docker\\config\\文件夹\\笔记");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        ArrayList<File> files1 = new ArrayList<>();
        ArrayList<File> files2 = new ArrayList<>();
        diGui(file,files1,files2);
        TreeMap<Long, File> tm = new TreeMap<>(new Comparator<Long>() {
            @Override
            public int compare(Long o1, Long o2) {
                return Long.compare(o1,o2);
            }
        });
        for (File file1 : files1) {
            tm.put(file1.lastModified(),file1);
        }
        //System.out.println(tm);
        Set<Long> keySet = tm.keySet();
       /* for (Long keys : keySet) {
            System.out.println(keys);
        }*/
        List<Long> list = keySet.stream().limit(10).collect(Collectors.toList());
        /*tm.forEach((l,f)->{
            System.out.println("修改时间："+sdf.format(aLong)+"-----文件路径:"+tm.get(aLong));
        });*/
        for (Long aLong : list) {
            System.out.println("修改时间："+sdf.format(aLong)+"-----文件路径:"+tm.get(aLong));
        }

    }
    private static void diGui(File file, ArrayList<File> files1, ArrayList<File> files2) {
        if (file!=null){
            for (File Files : file.listFiles()) {
                if (Files!=null){
                    if (Files.isFile()){
                        files1.add(Files);
                    }else{
                        files2.add(Files);
                        diGui(Files,files1,files2);
                    }
                }
            }
        }
    }
}
